# CMakeLists.txt for learn_boost

# Set CMake policy for Boost - use new Boost configuration
if(POLICY CMP0167)
    cmake_policy(SET CMP0167 NEW)
endif()

# Find Boost libraries using the new method (optional)
find_package(Boost QUIET)

if(Boost_FOUND)
    message(STATUS "Boost found: ${Boost_VERSION}")

    # Add asio subdirectory if it has content
    if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/asio" AND IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/asio")
        file(GLOB ASIO_SOURCES "asio/*.cpp")
        if(ASIO_SOURCES)
            add_subdirectory(asio)
        else()
            message(STATUS "asio directory is empty, skipping")
        endif()
    endif()

    # Create a placeholder target for future Boost examples
    add_custom_target(boost_examples
        COMMENT "Placeholder for Boost learning examples"
    )

else()
    message(WARNING "Boost not found. Install Boost to enable boost learning examples.")
    message(STATUS "On Ubuntu/Debian: sudo apt-get install libboost-all-dev")
    message(STATUS "On CentOS/RHEL: sudo yum install boost-devel")
    message(STATUS "On macOS: brew install boost")

    # Create a dummy target that explains how to install Boost
    add_custom_target(boost_examples
        COMMAND ${CMAKE_COMMAND} -E echo "Boost is not installed. Please install Boost libraries to run these examples."
        COMMENT "Boost not available"
    )
endif()

# Create asio subdirectory CMakeLists.txt if it doesn't exist
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/asio" AND IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/asio")
    if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/asio/CMakeLists.txt")
        file(WRITE "${CMAKE_CURRENT_SOURCE_DIR}/asio/CMakeLists.txt"
"# CMakeLists.txt for asio examples

# This directory is currently empty
# Add your Boost.Asio learning examples here

# Example of how to create an asio executable:
# add_executable(asio_example example.cpp)
# target_link_libraries(asio_example \${Boost_LIBRARIES})
# if(WIN32)
#     target_link_libraries(asio_example ws2_32 wsock32)
# endif()
")
    endif()
endif()
